var mapapi = require('../../commons/libmap.js')
const pageOptions = {
  // 页面数据
  data: {
    isFirstOnShow: true, // 是否为首次执行onShow
    storeCount:0,
    store:{},
    stores:[],
  },
  // 页面载入时
  onLoad(e) {
    this.init(e)
    console.log(e.loc)
    mapapi.getAllStores("东莞",e.loc).then(res=>{
      console.log(e.loc);
      console.log(res);
      this.setData({
        storesCount:res.count,
        stores:res.data,
      });
      console.log(this.data.stores);
      this.onShow();
    })
      
  },
  // 页面初始化
  init(e) {},
  // 页面准备好时
  onReady() {},
  // 页面显示时
  onShow() {
    const { isFirstOnShow } = this.data

    if (isFirstOnShow) {
      // 首次执行时
      this.setData({
        isFirstOnShow: false,
      })
      return
    }
  },
  // 页面隐藏时
  onHide() {},
  // 页面卸载时
  onUnload() {},
  // 下拉页面时
  onPullDownRefresh() {},
  // 到达页面底部时
  onReachBottom() {},
  // 页面滚动时
  onPageScroll() {},
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  },
  jumpMap:function(event){
    wx.navigateTo({
      url: '/pages/map/all/index?loc='+event.currentTarget.dataset.loc,
    })
  },
  openMap:function(event){
    console.log(event.currentTarget.dataset.item);
    var item = event.currentTarget.dataset.item;
    console.log(item);
    wx.openLocation({
      latitude: item.location.lat,
      longitude: item.location.lng,
      scale: 18,
      name: item.title,
      address: item.address,
      success: (result) => {
        console.log(item.title);
      },
      fail: () => {},
      complete: () => {}
    });
      

  },
}

Page(pageOptions)
